/**
 * 自定义函数
 * */

//var taskArys = [
//    {
//        id: 1, title: '拆除工', detail: '描述描述描述描述...', pubtime: '2025-05-05 12:12',
//        status: 1, status_name: '新下发', reply_txt: '反馈工作情况', reply_imgs: ['/h5/imgs/task-img.png']
//    }
//];
////任务列表
//function homeList(){
//    var h = '', i = 0, d = taskArys, ii, imgs;
//    for (; i < d.length; i ++) {
//        h += '<div class="tbox">';
//        h += '<span class="txt">';
//        h += '任务状态：' + d[i].status_name;
//        h += '</span>';
//        h += '<span class="btn">马上去做</span>';
//        h += '<div class="title">' + d[i].title + '</div>';
//        h += '<div class="pubtime">' + d[i].pubtime + '</div>';
//        h += '<table class="cnt">';
//        h += '<tr>';
//        h += '<td class="tdl">任务详情</td>';
//        h += '<td class="tdr">' + d[i].detail + '</td>';
//        h += '</tr>';
//        h += '<tr>';
//        h += '<td class="tdl">做的咋样</td>';
//        h += '<td class="tdr">';
//        if (d[i].reply_txt != '') {
//            h += d[i].reply_txt;
//        }
//        imgs = d[i].reply_imgs;
//        for (ii = 0; ii < imgs.length; ii ++) {
//            h += '<div><img src="' + imgs[i] + '" width="100"/> </div>';
//        }
//        h += '</td>';
//        h += '';
//        h += '</tr>';
//        h += '</table>';
//        h += '</div>';
//    }
//    $('#tbody').html(h);
//}


//首页列表
function getList(){
    var uinfo = getUserInfo();
    var formData = {
        role_id: uinfo.role_id, depart_id: uinfo.depart_id,
    };
    $.ajax({
        type: apiMethod,
        url: apiDomain + 'index/index',
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg});
                return
            }
            getHtml(res.data);
        },
        error: function () {
            console.log('网络错误');
        }
    });
}
//字符串
function getHtml(d){
    var uinfo = getUserInfo();
    var h = '', i = 0, ii, imgs, status;
    for (; i < d.length; i ++) {
        status = d[i].status;
        h += '<div class="tbox">';
        h += '<span class="txt">';
        h += '任务状态：' + d[i].status_name;
        h += '</span>';
        if (status == 2 && uinfo.role_id == 5) {
            h += '<span class="btn" onclick="auth_ok(' + d[i].id + ')">通过</span>';
            h += '<span class="btn" onclick="auth_no_pop(' + d[i].id + ');">拒绝</span>';
        }
        //if (status == 3 && (uinfo.role_id == 2 || uinfo.role_id == 3 || uinfo.role_id == 4)) {
        if (status == 3) {
            h += '<span class="btn" onclick="edit_pop(' + d[i].id + ');">修改</span>';
        }
        if (status == 4) {
            h += '<span class="btn" onclick="reply_pop(' + d[i].id + ');">马上去做</span>';
        }
        h += '<div class="title">' + d[i].title + '</div>';
        h += '<div class="pubtime">' + d[i].pubtime + '</div>';
        h += '<table class="cnt">';
        h += '<tr>';
        h += '<td class="tdl">任务详情</td>';
        h += '<td class="tdr">' + d[i].detail + '</td>';
        h += '</tr>';
        if (d[i].edit_txt != '') {
            h += '<tr>';
            h += '<td class="tdl">重新修改</td>';
            h += '<td class="tdr">' + d[i].edit_txt + '</td>';
            h += '</tr>';
        }
        if (d[i].status == 3) {
            h += '<tr>';
            h += '<td class="tdl">拒绝原因</td>';
            h += '<td class="tdr">';
            h += d[i].reply_txt;
            h += '</td>';
            h += '</tr>';
            h += '<tr>';
            h += '<td class="tdl">做的咋样</td>';
            h += '<td class="tdr">';
            h += '</td>';
            h += '</tr>';
        } else {
            h += '<tr>';
            h += '<td class="tdl">做的咋样</td>';
            h += '<td class="tdr">';
            h += d[i].reply_txt;
            imgs = d[i].reply_imgs;
            for (ii = 0; ii < imgs.length; ii ++) {
                h += '<div><img src="' + imgs[i] + '" width="100"/></div>';
            }
            h += '</td>';
            h += '</tr>';
        }
        h += '</table>';
        h += '</div>';
    }
    $('#tbody').html(h);
}


//审核拒绝
function auth_no_pop(v){
    var h = '';
    h += '<style type="text/css">.popMask { width: 100vw; height: 100vh; background: rgba(0,0,0,0.5); position: fixed; left: 0; top: 0; z-index: 100; } .popCnt { padding: 20px; width: 80vw; height: 100vh; background: #fff; color: #888; position: fixed; left: 0; top: 0; z-index: 100; }  .popCnt .btn { margin: 0 auto; width: 80%; } .popCnt button { padding: 5px 0; width: 45%; background: #0088cc; border: 0; border-radius: 3px; color: #fff; } .popCnt .btn .popClose { background: orangered; }</style>';
    h += '<div class="popMask"></div>';
    h += '<div class="popCnt" style="height: 180px;">';
    h += '<div>拒绝原因</div>';
    h += '<textarea style="border: 1px solid #0088CC;" id="remark"></textarea>';
    h += '<div class="btn">';
    h += '<button class="popClose" onclick="$(\'#formPop\').html(\'\');">取消</button> &nbsp;';
    h += '<button onclick="auth_no(' + v + ')">确定</button>';
    h += '</div>';
    h += '</div>';
    h += '';
    $('#formPop').html(h);
}


//审核拒绝
function auth_no(v){
    var remark = $('#remark').val();
    console.log(remark);
    var uinfo = getUserInfo();
    var formData = {
        id: v, uid: uinfo.uid,
        role_id: uinfo.role_id,
        depart_id: uinfo.depart_id,
        remark: remark,
    };
    if (remark == '') {
        msgPop({msg: '备注必须的'}); return
    }
    $.ajax({
        type: apiMethod,
        url: apiDomain + 'index/auth-no',
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code != 0) {
                msgPop({msg: res.msg});
                return
            }
            msgPop({msg: '成功'});
            setTimeout(function(){
                window.location.href = '';
            }, 500);
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//审核拒绝
function auth_ok(v){
    var uinfo = getUserInfo();
    var formData = {
        id: v, uid: uinfo.uid,
        role_id: uinfo.role_id,
        depart_id: uinfo.depart_id,
    };
    $.ajax({
        type: apiMethod,
        url: apiDomain + 'index/auth-ok',
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code != 0) {
                msgPop({msg: res.msg});
                return
            }
            msgPop({msg: '成功'});
            setTimeout(function(){
                window.location.href = '';
            }, 500);
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//编辑
function edit_pop(v){
    var h = '';
    h += '<style type="text/css">.popMask { width: 100vw; height: 100vh; background: rgba(0,0,0,0.5); position: fixed; left: 0; top: 0; z-index: 100; } .popCnt { padding: 20px; width: 80vw; height: 100vh; background: #fff; color: #888; position: fixed; left: 0; top: 0; z-index: 100; }  .popCnt .btn { margin: 0 auto; width: 80%; } .popCnt button { padding: 5px 0; width: 45%; background: #0088cc; border: 0; border-radius: 3px; color: #fff; } .popCnt .btn .popClose { background: orangered; }</style>';
    h += '<div class="popMask"></div>';
    h += '<div class="popCnt" style="height: 200px; overflow: auto;">';
    h += '<div>重新修改</div>';
    h += '<textarea style="border: 1px solid #0088CC;" id="remark"></textarea>';
    h += '<div class="btn">';
    h += '<button class="popClose" onclick="$(\'#formPop\').html(\'\');">取消</button> &nbsp;';
    h += '<button onclick="modify(' + v + ')">确定</button>';
    h += '</div>';
    h += '</div>';
    h += '';
    $('#formPop').html(h);
}


//重新修改
function modify(v){
    var remark = $('#remark').val();
    console.log(remark);
    var uinfo = getUserInfo();
    var formData = {
        id: v, uid: uinfo.uid,
        role_id: uinfo.role_id,
        depart_id: uinfo.depart_id,
        remark: remark,
    };
    if (remark == '') {
        msgPop({msg: '备注必须的'}); return
    }
    $.ajax({
        type: apiMethod,
        url: apiDomain + 'index/auth-modify',
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code != 0) {
                msgPop({msg: res.msg});
                return
            }
            msgPop({msg: '成功'});
            setTimeout(function(){
                window.location.href = '';
            }, 500);
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//回复弹窗
function reply_pop(v){
    var h = '';
    h += '<style type="text/css">.popMask { width: 100vw; height: 100vh; background: rgba(0,0,0,0.5); position: fixed; left: 0; top: 0; z-index: 100; } .popCnt { padding: 20px; width: 80vw; height: 100vh; background: #fff; color: #888; position: fixed; left: 0; top: 0; z-index: 100; }  .popCnt .btn { margin: 0 auto; width: 80%; } .popCnt button { padding: 5px 0; width: 45%; background: #0088cc; border: 0; border-radius: 3px; color: #fff; } .popCnt .btn .popClose { background: orangered; }</style>';
    h += '<div class="popMask"></div>';
    h += '<div class="popCnt" style="height: 200px; overflow: auto;">';
    h += '<div>做的怎么样</div>';
    h += '<textarea style="border: 1px solid #0088CC;" id="remark"></textarea>';
    h += '<div class="btn">';
    h += '<button class="popClose" onclick="$(\'#formPop\').html(\'\');">取消</button> &nbsp;';
    h += '<button onclick="reply(' + v + ')">确定</button>';
    h += '</div>';
    h += '</div>';
    h += '';
    $('#formPop').html(h);
}


//回复
function reply(v){
    var remark = $('#remark').val();
    console.log(remark);
    var uinfo = getUserInfo();
    var formData = {
        id: v, uid: uinfo.uid,
        role_id: uinfo.role_id,
        depart_id: uinfo.depart_id,
        remark: remark,
    };
    if (remark == '') {
        msgPop({msg: '备注必须的'}); return
    }
    $.ajax({
        type: apiMethod,
        url: apiDomain + 'index/auth-reply',
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code != 0) {
                msgPop({msg: res.msg});
                return
            }
            msgPop({msg: '成功'});
            setTimeout(function(){
                window.location.href = '';
            }, 500);
        },
        error: function () {
            console.log('网络错误');
        }
    });
}